﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace EmailMarketingCampaign
{
    public partial class KeepInTouch : System.Web.UI.Page
    {
        Table Table1;
        ScheduleControl sc = new ScheduleControl();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Table1 = new Table();

                TableRow th = new TableRow();

                TableCell tc1 = new TableCell();
                TableCell tc2 = new TableCell();

                th.Cells.Add(tc1);
                th.Cells.Add(tc2);

                Table1.Rows.Add(th);

                KeepTouchRow k1 = new KeepTouchRow(0, Session["COMUniquelID"].ToString());
                Table1.Rows.Add(k1);
                PlaceHolder1.Controls.Add(Table1);
                Session["table1"] = Table1;
            }
            else
            {
                Table1 = (Table)Session["table1"];
                PlaceHolder1.Controls.Add(Table1);

            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {

            KeepTouchRow k1 = new KeepTouchRow(Session["COMUniquelID"].ToString());
            Table1.Rows.Add(k1);
            Session["table1"] = Table1;

        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            Table1 = new Table();

            TableRow th = new TableRow();
            TableCell tc1 = new TableCell();
            TableCell tc2 = new TableCell();

            th.Cells.Add(tc1);
            th.Cells.Add(tc2);

            Table1.Rows.Add(th);

            KeepTouchRow k1 = new KeepTouchRow(0, Session["COMUniquelID"].ToString());

            Table1.Rows.Add(k1);

            Session["table1"] = Table1;

            Response.Redirect("KeepInTouch.aspx");
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            int i = 0;
            ArrayList a = new ArrayList();
            foreach (TableRow r in Table1.Rows)
            {
                Schedule s = new Schedule();
                try
                {
                    int day = int .Parse (((TextBox)r.Cells[0].FindControl("txtDay" + i)).Text);
                    int message = int .Parse (((DropDownList)r.Cells[1].FindControl("drMessage" + i)).SelectedValue);
                    s.setDay(day);
                    s.setEmailID(message);
                }
                
                
                catch (Exception ex)
                {
                    ex.ToString(); continue;
                }

                i++;

                a.Add(s);
            }


            sc.insertKeepInTouchDay(a);


        }
    }
}
